package com.app.controller;


import com.app.common.Result;
import com.app.model.BannerModel;
import com.app.service.BannerService;
import com.app.utils.CommonHelp;
import com.app.vo.BannerVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 轮播图
 * @author 16693103420
 * @since 2024-01-26
 */
@RestController
@RequestMapping("/banner")
public class BannerController {

    @Autowired
    private BannerService bannerService;

    // 查询列表
    @GetMapping("/getBannerList")
    public Result getBannerList(@RequestParam(defaultValue = "0") Integer page,
                                @RequestParam(defaultValue = "10") Integer limit, Integer type,Integer classification) {
        BannerVo BannerVo = bannerService.getBannerList(page, limit,type,classification);
        return Result.success(BannerVo);
    }

    //根据id查询
    @GetMapping("/getBannerById")
    public Result getBannerById(Integer id) {
        BannerModel Banner = bannerService.getById(id);
        return Result.success(Banner);
    }

    //新增和修改
    @PostMapping("/addAndUpdateBanner")
    public Result addAndUpdateBanner(@RequestBody BannerModel bannerModel) {
        BannerModel Banner = bannerService.getById(bannerModel.getId());
        if (Banner != null) {
            bannerModel.setUpdateTime(CommonHelp.getNowTimestamp());
            bannerService.updateById(bannerModel);
            return Result.success("修改成功");
        } else {
            bannerModel.setCreateTime(CommonHelp.getNowTimestamp());
            bannerService.save(bannerModel);
            return Result.success("添加成功");
        }
    }
    //根据id删除
    @GetMapping("/delBanner")
    public Result delBanner(Integer id) {
        bannerService.removeById(id);
        return Result.success("删除成功");
    }



}

